/*************************************************************
 * @file remote_cs2.h
 * @author MicroOrange
 * @brief 
 * @date 2023/2/19
 *************************************************************/

#ifndef LS_ARM_REMOTE_PS2_H
#define LS_ARM_REMOTE_PS2_H

#include "sorg_utils.h"
#include "stm32f1xx_hal.h"
#include "main.h"
#define DI HAL_GPIO_ReadPin(PS2_MISO_GPIO_Port, PS2_MISO_Pin)            // 输入引脚

#define DO_H HAL_GPIO_WritePin(PS2_MOSI_GPIO_Port, PS2_MOSI_Pin, GPIO_PIN_SET)        //命令位高
#define DO_L HAL_GPIO_WritePin(PS2_MOSI_GPIO_Port, PS2_MOSI_Pin, GPIO_PIN_RESET)       //命令位低

#define CS_H HAL_GPIO_WritePin(PS2_CS_GPIO_Port, PS2_CS_Pin, GPIO_PIN_SET)       //CS拉高
#define CS_L HAL_GPIO_WritePin(PS2_CS_GPIO_Port, PS2_CS_Pin, GPIO_PIN_RESET)       //CS拉低

#define CLK_H HAL_GPIO_WritePin(PS2_SCK_GPIO_Port, PS2_SCK_Pin, GPIO_PIN_SET)      //时钟拉高
#define CLK_L HAL_GPIO_WritePin(PS2_SCK_GPIO_Port, PS2_SCK_Pin, GPIO_PIN_RESET)      //时钟拉低


//手柄接口初始化    输入  DI->PA0
//                 输出  DO->PA1    CS->PA2  CLK->PA3

//These are our button constants
#define PSB_SELECT      1
#define PSB_L3          2
#define PSB_R3          3
#define PSB_START       4
#define PSB_PAD_UP      5
#define PSB_PAD_RIGHT   6
#define PSB_PAD_DOWN    7
#define PSB_PAD_LEFT    8
#define PSB_L2          9
#define PSB_R2          10
#define PSB_L1          11
#define PSB_R1          12
#define PSB_GREEN       13
#define PSB_RED         14
#define PSB_BLUE        15
#define PSB_PINK        16

#define PSB_TRIANGLE    13
#define PSB_CIRCLE      14
#define PSB_CROSS       15
#define PSB_SQUARE      16

//#define WHAMMY_BAR		8

//These are stick values
#define PSS_RX 5                //右摇杆X轴数据
#define PSS_RY 6
#define PSS_LX 7
#define PSS_LY 8

extern u8 Data[9];
extern u16 MASK[16];
extern u16 Handkey;
extern float PS2_LX,PS2_LY,PS2_RX,PS2_RY,PS2_KEY;         //PS2相关变量

void PS2_Init(void);
u8 PS2_RedLight(void);   //判断是否为红灯模式
void PS2_ReadData(void); //读手柄数据
void PS2_Cmd(u8 CMD);		  //向手柄发送命令
u8 PS2_DataKey(void);		  //按键值读取
u8 PS2_AnologData(u8 button); //得到一个摇杆的模拟量
void PS2_ClearData(void);	  //清除数据缓冲区
void PS2_Vibration(u8 motor1, u8 motor2);//振动设置motor1  0xFF开，其他关，motor2  0x40~0xFF

void PS2_EnterConfing(void);	 //进入配置
void PS2_TurnOnAnalogMode(void); //发送模拟量
void PS2_VibrationMode(void);    //振动设置
void PS2_ExitConfing(void);	     //完成配置
void PS2_SetInit(void);		     //配置初始化

void PS2_Read(void);  //读取PS2手柄的控制量

void remote_ps2_unit_test();

#endif //LS_ARM_REMOTE_PS2_H
